﻿


// Author:					Doan Quoc Tuan
// Created:					2013-5-21
// Last Modified:			2013-5-21
// 
// The use and distribution terms for this software are covered by the 
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)  
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by 
// the terms of this license.
//
// You must not remove this notice, or any other, from this software.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using SMSPanasonic.Data;

namespace SMSPanasonic.Business
{

    public class SmsMtStatistic
    {

        #region Constructors

        public SmsMtStatistic()
        { }


        public SmsMtStatistic(
            SqlGuid mtGuid)
        {
            GetSmsMtStatistic(
                mtGuid);
        }

        #endregion

        #region Private Properties

        private SqlGuid _mtGuid = SqlGuid.Null;
        private SqlGuid _moGuid = SqlGuid.Null;
        private SqlString _shortCode = SqlString.Null;
        private SqlString _destAddr = SqlString.Null;
        private SqlInt32 _operatorID = SqlInt32.Null;
        private SqlString _message = SqlString.Null;
        private SqlInt32 _cooperateID = SqlInt32.Null;
        private SqlString _status = SqlString.Null;
        private SqlDateTime _sentTime = SqlDateTime.Null;
        private SqlString _cDRIndicator = SqlString.Null;
        private SqlString _mTType = SqlString.Null;
        private SqlInt32 _retryOnFailReqTimes = SqlInt32.Null;
        private SqlInt32 _retryOnTimeOutReqTimes = SqlInt32.Null;
        private SqlInt64 _retryOnFailReqDuration = SqlInt64.Null;
        private SqlInt64 _retryOnTimeOutReqDuration = SqlInt64.Null;

        #endregion

        #region Public Properties

        public SqlGuid MtGuid
        {
            get { return _mtGuid; }
            set { _mtGuid = value; }
        }
        public SqlGuid MoGuid
        {
            get { return _moGuid; }
            set { _moGuid = value; }
        }
        public SqlString ShortCode
        {
            get { return _shortCode; }
            set { _shortCode = value; }
        }
        public SqlString DestAddr
        {
            get { return _destAddr; }
            set { _destAddr = value; }
        }
        public SqlInt32 OperatorID
        {
            get { return _operatorID; }
            set { _operatorID = value; }
        }
        public SqlString Message
        {
            get { return _message; }
            set { _message = value; }
        }
        public SqlInt32 CooperateID
        {
            get { return _cooperateID; }
            set { _cooperateID = value; }
        }
        public SqlString Status
        {
            get { return _status; }
            set { _status = value; }
        }
        public SqlDateTime SentTime
        {
            get { return _sentTime; }
            set { _sentTime = value; }
        }
        public SqlString CDRIndicator
        {
            get { return _cDRIndicator; }
            set { _cDRIndicator = value; }
        }
        public SqlString MTType
        {
            get { return _mTType; }
            set { _mTType = value; }
        }
        public SqlInt32 RetryOnFailReqTimes
        {
            get { return _retryOnFailReqTimes; }
            set { _retryOnFailReqTimes = value; }
        }
        public SqlInt32 RetryOnTimeOutReqTimes
        {
            get { return _retryOnTimeOutReqTimes; }
            set { _retryOnTimeOutReqTimes = value; }
        }
        public SqlInt64 RetryOnFailReqDuration
        {
            get { return _retryOnFailReqDuration; }
            set { _retryOnFailReqDuration = value; }
        }
        public SqlInt64 RetryOnTimeOutReqDuration
        {
            get { return _retryOnTimeOutReqDuration; }
            set { _retryOnTimeOutReqDuration = value; }
        }

        #endregion

        #region Private Methods

        /// <summary>
        /// Gets an instance of SmsMtStatistic.
        /// </summary>
        /// <param name="mtGuid"> mtGuid </param>
        private void GetSmsMtStatistic(
            SqlGuid mtGuid)
        {
            using (IDataReader reader = DBSmsMtStatistic.GetOne(
                mtGuid))
            {
                PopulateFromReader(reader);
            }

        }


        private void PopulateFromReader(IDataReader reader)
        {
            if (reader.Read())
            {
                if (!reader.IsDBNull(0)) this._mtGuid = reader.GetGuid(0);
                if (!reader.IsDBNull(1)) this._moGuid = reader.GetGuid(1);
                if (!reader.IsDBNull(2)) this._shortCode = reader.GetString(2);
                if (!reader.IsDBNull(3)) this._destAddr = reader.GetString(3);
                if (!reader.IsDBNull(4)) this._operatorID = reader.GetInt32(4);
                if (!reader.IsDBNull(5)) this._message = reader.GetString(5);
                if (!reader.IsDBNull(6)) this._cooperateID = reader.GetInt32(6);
                if (!reader.IsDBNull(7)) this._status = reader.GetString(7);
                if (!reader.IsDBNull(8)) this._sentTime = reader.GetDateTime(8);
                if (!reader.IsDBNull(9)) this._cDRIndicator = reader.GetString(9);
                if (!reader.IsDBNull(10)) this._mTType = reader.GetString(10);
                if (!reader.IsDBNull(11)) this._retryOnFailReqTimes = reader.GetInt32(11);
                if (!reader.IsDBNull(12)) this._retryOnTimeOutReqTimes = reader.GetInt32(12);
                if (!reader.IsDBNull(13)) this._retryOnFailReqDuration = reader.GetInt64(13);
                if (!reader.IsDBNull(14)) this._retryOnTimeOutReqDuration = reader.GetInt64(14);

            }

        }

        /// <summary>
        /// Persists a new instance of SmsMtStatistic. Returns true on success.
        /// </summary>
        /// <returns></returns>
        private bool Create()
        {
            this._mtGuid = Guid.NewGuid();

            int rowsAffected = DBSmsMtStatistic.Create(
                this._mtGuid,
                this._moGuid,
                this._shortCode,
                this._destAddr,
                this._operatorID,
                this._message,
                this._cooperateID,
                this._status,
                this._sentTime,
                this._cDRIndicator,
                this._mTType,
                this._retryOnFailReqTimes,
                this._retryOnTimeOutReqTimes,
                this._retryOnFailReqDuration,
                this._retryOnTimeOutReqDuration);

            return (rowsAffected > 0);

        }


        /// <summary>
        /// Updates this instance of SmsMtStatistic. Returns true on success.
        /// </summary>
        /// <returns>bool</returns>
        private bool Update()
        {

            return DBSmsMtStatistic.Update(
                this._mtGuid,
                this._moGuid,
                this._shortCode,
                this._destAddr,
                this._operatorID,
                this._message,
                this._cooperateID,
                this._status,
                this._sentTime,
                this._cDRIndicator,
                this._mTType,
                this._retryOnFailReqTimes,
                this._retryOnTimeOutReqTimes,
                this._retryOnFailReqDuration,
                this._retryOnTimeOutReqDuration);

        }





        #endregion

        #region Public Methods

        /// <summary>
        /// Saves this instance of SmsMtStatistic. Returns true on success.
        /// </summary>
        /// <returns>bool</returns>
        public bool Save()
        {
            if (this._mtGuid != Guid.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
        }




        #endregion

        #region Static Methods

        /// <summary>
        /// Deletes an instance of SmsMtStatistic. Returns true on success.
        /// </summary>
        /// <param name="mtGuid"> mtGuid </param>
        /// <returns>bool</returns>
        public static bool Delete(
            SqlGuid mtGuid)
        {
            return DBSmsMtStatistic.Delete(
                mtGuid);
        }


        /// <summary>
        /// Gets a count of SmsMtStatistic. 
        /// </summary>
        public static int GetCount(string sWhereCondition)
        {
            return DBSmsMtStatistic.GetCount(sWhereCondition);
        }

        private static List<SmsMtStatistic> LoadListFromReader(IDataReader reader)
        {
            List<SmsMtStatistic> _smsMtStatisticList = new List<SmsMtStatistic>();
            try
            {
                while (reader.Read())
                {
                    SmsMtStatistic _smsMtStatistic = new SmsMtStatistic();
                    if (!reader.IsDBNull(0)) _smsMtStatistic._mtGuid = reader.GetGuid(0);

                    if (!reader.IsDBNull(1)) _smsMtStatistic._moGuid = reader.GetGuid(1);

                    if (!reader.IsDBNull(2)) _smsMtStatistic._shortCode = reader.GetString(2);

                    if (!reader.IsDBNull(3)) _smsMtStatistic._destAddr = reader.GetString(3);

                    if (!reader.IsDBNull(4)) _smsMtStatistic._operatorID = reader.GetInt32(4);

                    if (!reader.IsDBNull(5)) _smsMtStatistic._message = reader.GetString(5);

                    if (!reader.IsDBNull(6)) _smsMtStatistic._cooperateID = reader.GetInt32(6);

                    if (!reader.IsDBNull(7)) _smsMtStatistic._status = reader.GetString(7);

                    if (!reader.IsDBNull(8)) _smsMtStatistic._sentTime = reader.GetDateTime(8);

                    if (!reader.IsDBNull(9)) _smsMtStatistic._cDRIndicator = reader.GetString(9);

                    if (!reader.IsDBNull(10)) _smsMtStatistic._mTType = reader.GetString(10);

                    if (!reader.IsDBNull(11)) _smsMtStatistic._retryOnFailReqTimes = reader.GetInt32(11);

                    if (!reader.IsDBNull(12)) _smsMtStatistic._retryOnTimeOutReqTimes = reader.GetInt32(12);

                    if (!reader.IsDBNull(13)) _smsMtStatistic._retryOnFailReqDuration = reader.GetInt64(13);

                    if (!reader.IsDBNull(14)) _smsMtStatistic._retryOnTimeOutReqDuration = reader.GetInt64(14);

                    _smsMtStatisticList.Add(_smsMtStatistic);

                }
            }
            finally
            {
                reader.Close();
            }

            return _smsMtStatisticList;

        }

        /// <summary>
        /// Gets an IList with all instances of SmsMtStatistic.
        /// </summary>
        public static List<SmsMtStatistic> GetAll()
        {
            IDataReader reader = DBSmsMtStatistic.GetAll();
            return LoadListFromReader(reader);

        }

        /// <summary>
        /// Gets an IList with page of instances of SmsMtStatistic.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="totalPages">total pages</param>
        public static List<SmsMtStatistic> GetPage(string sWhereCondition, string sOrderBy, int pageNumber, int pageSize, out int totalPages)
        {
            totalPages = 1;
            IDataReader reader = DBSmsMtStatistic.GetPage(sWhereCondition, sOrderBy, pageNumber, pageSize, out totalPages);
            return LoadListFromReader(reader);
        }

        public static void Insert(DataTable dtSource)
        {
            DBSQLCommand.BulkCopy("SmsMtStatistic", dtSource);
        }
        #endregion

        #region Comparison Methods

        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByShortCode(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.ShortCode.CompareTo(_smsMtStatistic2.ShortCode);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByDestAddr(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.DestAddr.CompareTo(_smsMtStatistic2.DestAddr);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByOperatorID(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.OperatorID.CompareTo(_smsMtStatistic2.OperatorID);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByMessage(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.Message.CompareTo(_smsMtStatistic2.Message);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByCooperateID(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.CooperateID.CompareTo(_smsMtStatistic2.CooperateID);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByStatus(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.Status.CompareTo(_smsMtStatistic2.Status);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareBySentTime(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.SentTime.CompareTo(_smsMtStatistic2.SentTime);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByCDRIndicator(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.CDRIndicator.CompareTo(_smsMtStatistic2.CDRIndicator);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByMTType(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.MTType.CompareTo(_smsMtStatistic2.MTType);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByRetryOnFailReqTimes(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.RetryOnFailReqTimes.CompareTo(_smsMtStatistic2.RetryOnFailReqTimes);
        }
        /// <summary>
        /// Compares 2 instances of SmsMtStatistic.
        /// </summary>
        public static int CompareByRetryOnTimeOutReqTimes(SmsMtStatistic _smsMtStatistic1, SmsMtStatistic _smsMtStatistic2)
        {
            return _smsMtStatistic1.RetryOnTimeOutReqTimes.CompareTo(_smsMtStatistic2.RetryOnTimeOutReqTimes);
        }

        #endregion


    }

}





